#!/bin/bash
t=0
for i in `seq 1 40`
	do x=`wget -t 3 -w 3 -T 3 -q http://uoladmin:sun123@a4-vitoria$i.host.intranet:8086/connectioncounts -O - |awk -F\> '{print $3}' |awk -F\< '{print $1}'`
	x=`echo -n $x`
	#echo  "vitoria$i:$x"
	let t+=$x
done

gdata=2880

##date time vitoria_1  vitoria_2  vitoria_3  vitoria_4  vitoria_5  vitoria_6  vitoria_7  vitoria_8  vitoria_9  vitoria_10
#06/02/2009 09:16:49 16  6  15  5  14  4  17  3  14  4

#data=`date "+%d/%m/%Y %H:%M:%S"`
data=`date "+%H:%M:%S"`

echo "$data" >> /export/htdocs/alta.portal.intranet/audiencias/online2/x.dat
echo "$t" >> /export/htdocs/alta.portal.intranet/audiencias/online2/y.dat
tail -$gdata /export/htdocs/alta.portal.intranet/audiencias/online2/x.dat >> /export/htdocs/alta.portal.intranet/audiencias/online2/x.dat.swp
mv /export/htdocs/alta.portal.intranet/audiencias/online2/x.dat.swp /export/htdocs/alta.portal.intranet/audiencias/online2/x.dat
tail -$gdata /export/htdocs/alta.portal.intranet/audiencias/online2/y.dat >> /export/htdocs/alta.portal.intranet/audiencias/online2/y.dat.swp
mv /export/htdocs/alta.portal.intranet/audiencias/online2/y.dat.swp /export/htdocs/alta.portal.intranet/audiencias/online2/y.dat


xarray=`cat /export/htdocs/alta.portal.intranet/audiencias/online2/x.dat |xargs |sed -e "s/ /','/g"`
yarray=`cat /export/htdocs/alta.portal.intranet/audiencias/online2/y.dat |xargs |sed -e "s/ /','/g"`



echo "
<?php

// use the chart class to build the chart:
include_once( 'ofc-library/open-flash-chart.php' );
\$g = new graph();
\$g->bg_colour = '#FFFFFF';
\$g->title( 'Streaming - Usuarios OnLine ', '{font-size: 26px;}' );
\$g->set_data( array('$yarray') );
\$g->set_x_labels( array('$xarray' ) );
\$g->set_x_label_style( 14, '#E80000', 0, 200, '#00A000' );
\$g->set_x_axis_steps( 100 );
\$g->set_x_legend( 'Hora', 14, '#E80000' );
\$g->line( 2, '#E80000', 'Usuarios Simultaneos', 10 );
\$g->set_y_max( 50000 );
\$g->y_label_steps( 50 );
\$g->set_y_legend( 'Usuarios Simultaneos', 14, '#E80000' );
\$g->set_x_axis_steps( 100 );

// display the data
echo \$g->render();
?> 
" > /export/htdocs/alta.portal.intranet/audiencias/online2/online.php

